package com.baor.vip.service.impl;

import com.baor.vip.domain.BlackChangeDTO;
import com.baor.vip.domain.BlackChangeVO;
import com.baor.vip.domain.BlackChangeDTO;
import com.baor.vip.mapper.BlackMapper;
import com.baor.vip.service.BlackService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.baor.common.utils.PageUtils.startPage;

@Service
public class BlackServiceImpl implements BlackService {
    @Autowired
    private BlackMapper blackMapper;

    //会员余额列表
    @Override
    public Map<String, Object> selectBlackVOList(BlackChangeDTO blackChangeDTO) {
        BlackChangeVO blackChangeVO = blackMapper.totalBlack();
        startPage();
        List<BlackChangeDTO> blackChangeList = blackMapper.blackList(blackChangeDTO);
        PageInfo<BlackChangeDTO> pageInfo = new PageInfo<>(blackChangeList);

        Map<String,Object> map = new HashMap<>();
        map.put("blackChangeVO",blackChangeVO);
        map.put("blackChangeList",pageInfo);
        return map;
    }

    //余额开源/用途下拉框
    @Override
    public List<String> blackOrginBox() {
        return blackMapper.blackOrginBox();
    }
    //余额账户来源下拉框
    @Override
    public List<String> accTypeBox() {
        return blackMapper.accTypeBox();
    }

    @Override
    public int addBlack(BlackChangeVO blackChangeVO) {
        int ok1 = 0;
        int ok2 = 0;
        if(blackChangeVO.getVipUid() != null){
            ok1 = blackMapper.addBlackChange(blackChangeVO);
        }
        Map<String,Object> map = new HashMap<>();
        map.put("vipUid",blackChangeVO.getVipUid());
        map.put("blackChange",blackChangeVO.getBlackChange());
        if(ok1 > 0){
            if(blackMapper.select(blackChangeVO.getVipUid()) == 1){
                ok2 = blackMapper.updateVipBlack(map);
            }else {
                ok2 = blackMapper.addVipBlack(map);
            }
        }
        if(ok1 == 1 && ok2 == 1){
            return 1;
        }
        return 0;
    }
}
